/*
 * LogDate.java
 *
 * Created on July 11, 2006, 7:57 AM
 *
 * Brigham Young University - Idaho
 *
 */

package org.vcboard.model;

import java.sql.*;
import java.text.*;
import org.vcboard.WorkTimer;

/**
 *
 * @author Josh VanderLinden
 */
public class LogDate
{
   private Timestamp timeStamp = null;
   
   /** Creates a new instance of LogDate */
   public LogDate()
   {
   }
   
   public LogDate(LogDate aLogDate)
   {
      timeStamp = aLogDate.getTimestamp();
   }
   
   public LogDate(Timestamp aTimestamp)
   {
      timeStamp = aTimestamp;
   }
   
   public LogDate(long aTime)
   {
      setTimeInSeconds(aTime);
   }

   public Timestamp getTimestamp()
   {
      if (timeStamp == null)
      {
         timeStamp = new Timestamp(0);
      }
      //timeStamp.setTime(timeStamp.getTime() + (WorkTimer.getUser().getOffset() * 3600));
      
      return timeStamp;
   }
   
   public long getTimeInSeconds()
   {
      long tmp = -1;
      if (getTimestamp() != null)
      {
         tmp = (long) Math.ceil(getTimestamp().getTime() / 1000);
      }
      return tmp;
   }
   
   public long getTimeInMillis()
   {
      return getTimestamp().getTime() + (WorkTimer.getUser().getOffset() * 3600000);
   }
   
   public void setTimeInMillis(long time)
   {
      timeStamp = new Timestamp(time);
   }

   public void setTimeInSeconds(long time)
   {
      getTimestamp().setTime(time * 1000);
   }
   
   public int getDay()
   {
      Format day = new SimpleDateFormat("dd");
      return Integer.parseInt(day.format(getTimeInMillis()));
   }
   
   public int getMonth()
   {
      Format month = new SimpleDateFormat("MM");
      return Integer.parseInt(month.format(getTimeInMillis()));
   }
   
   public int getYear()
   {
      Format year = new SimpleDateFormat("yyyy");
      return Integer.parseInt(year.format(getTimeInMillis()));
   }
   
   public int getHours()
   {
      Format hour = new SimpleDateFormat("HH");
      return Integer.parseInt(hour.format(getTimeInMillis()));
   }
   
   public int getMinutes()
   {
      Format minute = new SimpleDateFormat("mm");
      return Integer.parseInt(minute.format(getTimeInMillis()));
   }
   
   public int getSeconds()
   {
      Format second = new SimpleDateFormat("ss");
      return Integer.parseInt(second.format(getTimeInMillis()));
   }
   
   public String getTime()
   {
      return getTime("HH:mm");
   }
   
   public String getDate()
   {
      return getTime("dd MMM yyy");
   }
   
   public String getFullDate()
   {
      return getTime("E, dd MMM yyyy HH:mm");
   }
   
   public String getTime(String format)
   {
      Format output = new SimpleDateFormat(format);
      Date input = new Date(getTimeInMillis());
      return output.format(input);
   }
   
   public String toString()
   {
      /*
      Format output = new SimpleDateFormat("E, dd MMM yyyy HH:mm");
      Date input = new Date(getTimeInMillis());
      return output.format(input);
       */
      return getDate();
   }
}
